﻿@model ProductModel

@using Telerik.Web.Mvc.UI;

@Html.ValidationSummary(false)
@Html.HiddenFor(model => model.Id)
@Html.Telerik().TabStrip().Name("product-edit").Items(x =>
{
    x.Add().Text(T("Admin.Catalog.Products.Info").Text).Content(TabInfo().ToHtmlString()).Selected(true);
    x.Add().Text(T("Admin.Common.SEO").Text).Content(TabSeo().ToHtmlString());
    if (Model.Id > 0)
    {
        x.Add().Text(T("Admin.Catalog.Products.Variants").Text).Content(TabVariants().ToHtmlString());
    }
    else
    {
        x.Add().Text(T("Admin.Catalog.Products.FirstVariant").Text).Content(TabFirstVariantInfo().ToHtmlString());
    }
    x.Add().Text(T("Admin.Catalog.Products.Categories").Text).Content(TabCategories().ToHtmlString());
    x.Add().Text(T("Admin.Catalog.Products.Manufacturers").Text).Content(TabManufacturers().ToHtmlString());
    x.Add().Text(T("Admin.Catalog.Products.RelatedProducts").Text).Content(TabRelatedProducts().ToHtmlString());
    x.Add().Text(T("Admin.Catalog.Products.CrossSells").Text).Content(TabCrossSells().ToHtmlString());
    x.Add().Text(T("Admin.Catalog.Products.Pictures").Text).Content(TabPictures().ToHtmlString());
    x.Add().Text(T("Admin.Catalog.Products.SpecificationAttributes").Text).Content(TabSpecificationAttributes().ToHtmlString());
})
@helper TabInfo()
    { 
    @(Html.LocalizedEditor<ProductModel, ProductLocalizedModel>("product-info-localized",
                @<table class="adminContent">
                    <tr>
                        <td class="adminTitle">
                            @Html.NopLabelFor(model => model.Locales[item].Name):
                        </td>
                        <td class="adminData">
                            @Html.EditorFor(model => Model.Locales[item].Name)
                            @Html.ValidationMessageFor(model => model.Locales[item].Name)
                        </td>
                    </tr>
                    <tr>
                        <td class="adminTitle">
                            @Html.NopLabelFor(model => model.Locales[item].ShortDescription):
                        </td>
                        <td class="adminData">
                            @Html.TextAreaFor(model => model.Locales[item].ShortDescription)
                            @Html.ValidationMessageFor(model => model.Locales[item].ShortDescription)
                        </td>
                    </tr>
                    <tr>
                        <td class="adminTitle">
                            @Html.NopLabelFor(model => model.Locales[item].FullDescription):
                        </td>
                        <td class="adminData">
                            @Html.EditorFor(model => model.Locales[item].FullDescription, "RichEditor")
                            @Html.ValidationMessageFor(model => model.Locales[item].FullDescription)
                        </td>
                    </tr>
                    <tr>
                        <td colspan="2">
                            @Html.HiddenFor(model => model.Locales[item].LanguageId)
                        </td>
                    </tr>
                </table>
                ,
                @<table class="adminContent">
                    <tr>
                        <td class="adminTitle">
                            @Html.NopLabelFor(model => model.Name):
                        </td>
                        <td class="adminData">
                            @Html.EditorFor(model => model.Name)
                            @Html.ValidationMessageFor(model => model.Name)
                        </td>
                    </tr>
                    <tr>
                        <td class="adminTitle">
                            @Html.NopLabelFor(model => model.ShortDescription):
                        </td>
                        <td class="adminData">
                            @Html.TextAreaFor(x => x.ShortDescription)
                            @Html.ValidationMessageFor(model => model.ShortDescription)
                        </td>
                    </tr>
                    <tr>
                        <td class="adminTitle">
                            @Html.NopLabelFor(model => model.FullDescription):
                        </td>
                        <td class="adminData">
                            @Html.EditorFor(x => x.FullDescription, "RichEditor")
                            @Html.ValidationMessageFor(model => model.FullDescription)
                        </td>
                    </tr>
                </table>
            ))
    <table class="adminContent">
        <tr>
            <td class="adminTitle">
                @Html.NopLabelFor(model => model.AdminComment):
            </td>
            <td class="adminData">
                @Html.TextAreaFor(model => model.AdminComment)
                @Html.ValidationMessageFor(model => model.AdminComment)
            </td>
        </tr>
        <tr>
            <td class="adminTitle">
                @Html.NopLabelFor(model => model.ProductTemplateId):
            </td>
            <td class="adminData">
                @Html.DropDownListFor(model => model.ProductTemplateId, Model.AvailableProductTemplates)
                @Html.ValidationMessageFor(model => model.ProductTemplateId)
            </td>
        </tr>
        <tr>
            <td class="adminTitle">
                @Html.NopLabelFor(model => model.ShowOnHomePage):
            </td>
            <td class="adminData">
                @Html.EditorFor(model => model.ShowOnHomePage)
                @Html.ValidationMessageFor(model => model.ShowOnHomePage)
            </td>
        </tr>
        <tr>
            <td class="adminTitle">
                @Html.NopLabelFor(model => model.Published):
            </td>
            <td class="adminData">
                @Html.EditorFor(model => model.Published)
                @Html.ValidationMessageFor(model => model.Published)
            </td>
        </tr>
        <tr>
            <td class="adminTitle">
                @Html.NopLabelFor(model => model.AllowCustomerReviews):
            </td>
            <td class="adminData">
                @Html.EditorFor(model => model.AllowCustomerReviews)
                @Html.ValidationMessageFor(model => model.AllowCustomerReviews)
            </td>
        </tr>
        <tr>
            <td class="adminTitle">
                @Html.NopLabelFor(model => model.ProductTags):
            </td>
            <td class="adminData">
                @Html.EditorFor(model => model.ProductTags)
                @Html.ValidationMessageFor(model => model.ProductTags)
            </td>
        </tr>
    </table>
}
@helper TabFirstVariantInfo()
    {
        var dataDictFpv = new ViewDataDictionary();
        dataDictFpv.TemplateInfo.HtmlFieldPrefix = "FirstProductVariantModel";
        @Html.Partial("_ProductVariantInfo", @Model.FirstProductVariantModel, dataDictFpv)
}
@helper TabSeo()
    {
    @(Html.LocalizedEditor<ProductModel, ProductLocalizedModel>("product-seo-localized",
               @<table class="adminContent">
                   <tr>
                       <td class="adminTitle">
                           @Html.NopLabelFor(model => model.Locales[item].MetaKeywords):
                       </td>
                       <td class="adminData">
                           @Html.EditorFor(model => model.Locales[item].MetaKeywords)
                           @Html.ValidationMessageFor(model => model.Locales[item].MetaKeywords)
                       </td>
                   </tr>
                   <tr>
                       <td class="adminTitle">
                           @Html.NopLabelFor(model => model.Locales[item].MetaDescription):
                       </td>
                       <td class="adminData">
                           @Html.TextAreaFor(model => model.Locales[item].MetaDescription)
                           @Html.ValidationMessageFor(model => model.Locales[item].MetaDescription)
                       </td>
                   </tr>
                   <tr>
                       <td class="adminTitle">
                           @Html.NopLabelFor(model => model.Locales[item].MetaTitle):
                       </td>
                       <td class="adminData">
                           @Html.TextAreaFor(model => model.Locales[item].MetaTitle)
                           @Html.ValidationMessageFor(model => model.Locales[item].MetaTitle)
                       </td>
                   </tr>
                   <tr>
                       <td class="adminTitle">
                           @Html.NopLabelFor(model => model.Locales[item].SeName):
                       </td>
                       <td class="adminData">
                           @Html.TextAreaFor(model => model.Locales[item].SeName)
                           @Html.ValidationMessageFor(model => model.Locales[item].SeName)
                       </td>
                   </tr>
                   <tr>
                       <td colspan="2">
                           @Html.HiddenFor(model => model.Locales[item].LanguageId)
                       </td>
                   </tr>
               </table>
               ,
               @<table class="adminContent">
                   <tr>
                       <td class="adminTitle">
                           @Html.NopLabelFor(model => model.MetaKeywords):
                       </td>
                       <td class="adminData">
                           @Html.EditorFor(x => x.MetaKeywords)
                           @Html.ValidationMessageFor(model => model.MetaKeywords)
                       </td>
                   </tr>
                   <tr>
                       <td class="adminTitle">
                           @Html.NopLabelFor(model => model.MetaDescription):
                       </td>
                       <td class="adminData">
                           @Html.TextAreaFor(x => x.MetaDescription)
                           @Html.ValidationMessageFor(model => model.MetaDescription)
                       </td>
                   </tr>
                   <tr>
                       <td class="adminTitle">
                           @Html.NopLabelFor(model => model.MetaTitle):
                       </td>
                       <td class="adminData">
                           @Html.TextAreaFor(x => x.MetaTitle)
                           @Html.ValidationMessageFor(model => model.MetaTitle)
                       </td>
                   </tr>
                   <tr>
                       <td class="adminTitle">
                           @Html.NopLabelFor(model => model.SeName):
                       </td>
                       <td class="adminData">
                           @Html.TextAreaFor(x => x.SeName)
                           @Html.ValidationMessageFor(model => model.SeName)
                       </td>
                   </tr>
               </table>))
}
@helper TabVariants()
    {
    @(Html.Telerik().Grid(Model.ProductVariantModels).Name("product-variants")
    .Columns(columns =>
    {
        columns.Bound(x => x.Name);
        columns.Bound(x => x.Sku);
        columns.Bound(x => x.Price);
        columns.Bound(x => x.DisplayOrder)
            .Centered(); 
        columns.Bound(x => x.Published)
            .Filterable(false)
            .Template(x => x.Published.ToString().ToLower())
            .Centered();
        columns.Template((x) => Html.ActionLink(T("Admin.Common.Edit").ToString(), "Edit", "ProductVariant", new { id = x.Id }, new { })).Title(T("Admin.Common.Edit").ToString());
    })
    .Footer(false))
    <div class="clear">
    </div>
    <a href="@Url.Action("Create", "ProductVariant", new { productId= Model.Id })" class="t-button">@T("Admin.Catalog.Products.Variants.AddNew")</a>
}
@helper TabCategories()
    {
    if (Model.Id > 0)
    {
        if (Model.NumberOfAvailableCategories > 0)
        {
                @(Html.Telerik().Grid<ProductModel.ProductCategoryModel>()
                    .Name("productcategories-grid")
                       .DataKeys(keys =>
                       {
                           keys.Add(x => x.Id);
                       })
                       .DataBinding(dataBinding =>
                       {
                           dataBinding.Ajax()
                               .Select("ProductCategoryList", "Product", new { productId = Model.Id })
                               .Insert("ProductCategoryInsert", "Product", new { productId = Model.Id })
                               .Update("ProductCategoryUpdate", "Product")
                               .Delete("ProductCategoryDelete", "Product");
                       })
                       .Columns(columns =>
                       {
                           columns.Bound(x => x.Category)
                               .Width(500)
                               .Centered();
                           columns.Bound(x => x.IsFeaturedProduct)
                               .Width(100)
                               .Centered();
                           columns.Bound(x => x.DisplayOrder)
                               .Width(100);
                           columns.Command(commands =>
                           {
                               commands.Edit();
                               commands.Delete();
                           })
                           .Width(180);
                       })
                       .ToolBar(commands => commands.Insert())
                       .ClientEvents(events => events.OnEdit("onProductCategoryEdit"))
                       .EnableCustomBinding(true))
    
                <script type="text/javascript">
                    function onProductCategoryEdit(e) {
                        $(e.form).find('#Category').data('tDropDownList').select(function (dataItem) {
                            return dataItem.Value == e.dataItem['CategoryId'];
                        });
                    }
                </script>
        }
        else
        {
                    @T("Admin.Catalog.Products.Categories.NoCategoriesAvailable")
        }
    }
    else
    {
            @T("Admin.Catalog.Products.Categories.SaveBeforeEdit")
    }
        
}
@helper TabManufacturers()
    {
    if (Model.Id > 0)
    {
        if (Model.NumberOfAvailableManufacturers > 0)
        {
                @(Html.Telerik().Grid<ProductModel.ProductManufacturerModel>()
                    .Name("productmanufacturers-grid")
                       .DataKeys(keys =>
                       {
                           keys.Add(x => x.Id);
                       })
                       .DataBinding(dataBinding =>
                       {
                           dataBinding.Ajax()
                               .Select("ProductManufacturerList", "Product", new { productId = Model.Id })
                               .Insert("ProductManufacturerInsert", "Product", new { productId = Model.Id })
                               .Update("ProductManufacturerUpdate", "Product")
                               .Delete("ProductManufacturerDelete", "Product");
                       })
                       .Columns(columns =>
                       {
                           columns.Bound(x => x.Manufacturer)
                               .Width(500)
                               .Centered();
                           columns.Bound(x => x.IsFeaturedProduct)
                               .Width(100)
                               .Centered();
                           columns.Bound(x => x.DisplayOrder)
                               .Width(100);
                           columns.Command(commands =>
                           {
                               commands.Edit();
                               commands.Delete();
                           })
                           .Width(180);
                       })
                       .ToolBar(commands => commands.Insert())
                       .ClientEvents(events => events.OnEdit("onProductManufacturerEdit"))
                       .EnableCustomBinding(true))
    
                <script type="text/javascript">
                    function onProductManufacturerEdit(e) {
                        $(e.form).find('#Manufacturer').data('tDropDownList').select(function (dataItem) {
                            return dataItem.Value == e.dataItem['ManufacturerId'];
                        });
                    }
                </script>
        }
        else
        {
                @T("Admin.Catalog.Products.Manufacturers.NoManufacturersAvailable")
        }
    }
    else
    {
            @T("Admin.Catalog.Products.Manufacturers.SaveBeforeEdit")
    }
        
}
@helper TabRelatedProducts()
    {
    if (Model.Id > 0)
    {
            
            <table class="adminContent">
                <tr>
                    <td>
            @(Html.Telerik().Grid<ProductModel.RelatedProductModel>()
                .Name("relatedproducts-grid")
                    .DataKeys(keys =>
                    {
                        keys.Add(x => x.Id);
                    })
                    .DataBinding(dataBinding =>
                    {
                        dataBinding.Ajax()
                            .Select("RelatedProductList", "Product", new { productId = Model.Id })
                            .Update("RelatedProductUpdate", "Product")
                            .Delete("RelatedProductDelete", "Product");
                    })
                    .Columns(columns =>
                    {
                        columns.Bound(x => x.Product2Name)
                            .Width(500)
                            .ReadOnly();
                        columns.Bound(x => x.DisplayOrder)
                            .Width(100)
                            .Centered();
                        columns.Command(commands =>
                        {
                            commands.Edit();
                            commands.Delete();
                        })
                        .Width(180);
                    })
                    .EnableCustomBinding(true))
                    </td>
                </tr>
                <tr>
                    <td width="100%">
                        <input type="submit" id="btnAddNewRelatedProduct" name="btnAddNewRelatedProduct" value="@T("Admin.Catalog.Products.RelatedProducts.AddNew")" onclick="javascript:OpenWindow('@(Url.Action("RelatedProductAddPopup", "Product", new { productId = Model.Id, btnId = "btnRefreshRelatedProducts", formId = "product-form" }))', 800, 700, true); return false;" class="t-button" />
                        <input type="submit" id="btnRefreshRelatedProducts" name="btnRefreshRelatedProducts" style="display: none" />
                        <script type="text/javascript">
                            $(document).ready(function () {
                                $('#btnRefreshRelatedProducts').click(function () {
                                    //refresh grid
                                    var optionsGrid = $("#relatedproducts-grid");
                                    optionsGrid.data('tGrid').ajaxRequest();

                                    //return false to don't reload a page
                                    return false;
                                });
                            });
                        </script>
                    </td>
                </tr>
            </table>
    }
    else
    {
            @T("Admin.Catalog.Products.RelatedProducts.SaveBeforeEdit")
    }
        
}
@helper TabCrossSells()
    {
    if (Model.Id > 0)
    {
            
            <table class="adminContent">
                <tr>
                    <td>
            @(Html.Telerik().Grid<ProductModel.CrossSellProductModel>()
                .Name("crosssellproducts-grid")
                    .DataKeys(keys =>
                    {
                        keys.Add(x => x.Id);
                    })
                    .DataBinding(dataBinding =>
                    {
                        dataBinding.Ajax()
                            .Select("CrossSellProductList", "Product", new { productId = Model.Id })
                            .Delete("CrossSellProductDelete", "Product");
                    })
                    .Columns(columns =>
                    {
                        columns.Bound(x => x.Product2Name)
                            .Width(500)
                            .ReadOnly();
                        columns.Command(commands =>
                        {
                            commands.Delete();
                        })
                        .Width(180);
                    })
                    .EnableCustomBinding(true))
                    </td>
                </tr>
                <tr>
                    <td width="100%">
                        <input type="submit" id="btnAddNewCrossSellProduct" name="btnAddNewCrossSellProduct" value="@T("Admin.Catalog.Products.CrossSells.AddNew")" onclick="javascript:OpenWindow('@(Url.Action("CrossSellProductAddPopup", "Product", new { productId = Model.Id, btnId = "btnRefreshCrossSellProducts", formId = "product-form" }))', 800, 700, true); return false;" class="t-button" />
                        <input type="submit" id="btnRefreshCrossSellProducts" name="btnRefreshCrossSellProducts" style="display: none" />
                        <script type="text/javascript">
                            $(document).ready(function () {
                                $('#btnRefreshCrossSellProducts').click(function () {
                                    //refresh grid
                                    var optionsGrid = $("#crosssellproducts-grid");
                                    optionsGrid.data('tGrid').ajaxRequest();

                                    //return false to don't reload a page
                                    return false;
                                });
                            });
                        </script>
                    </td>
                </tr>
            </table>
    }
    else
    {
            @T("Admin.Catalog.Products.CrossSells.SaveBeforeEdit")
    }
        
}
@helper TabPictures()
    {
        if (Model.Id > 0)
        {
            <div>
            @(Html.Telerik().Grid<ProductModel.ProductPictureModel>()
                    .Name("productpictures-grid")
                    .DataKeys(x =>
                    {
                        x.Add(y => y.Id).RouteKey("Id");
                    })
                    .Columns(columns =>
                    {
                        columns.Bound(x => x.PictureUrl)
                            .Width(400)
                            .ClientTemplate("<img alt='<#= Id #>' src='<#= PictureUrl #>' />")
                            .ReadOnly();
                        columns.Bound(x => x.DisplayOrder).Width(100);
                        columns.Command(commands =>
                        {
                            commands.Edit();
                            commands.Delete();
                        }).Width(180);

                    })
                    .Editable(x =>
                    {
                        x.Mode(GridEditMode.InLine);
                    })
                    .DataBinding(dataBinding =>
                    {
                        dataBinding.Ajax().Select("ProductPictureList", "Product", new { productId = Model.Id })
                            .Update("ProductPictureUpdate", "Product")
                            .Delete("ProductPictureDelete", "Product");
                    })
                    .EnableCustomBinding(true))
        </div>
            <p>
                <strong>@T("Admin.Catalog.Products.Pictures.AddNew")</strong>
            </p>
            <script type="text/javascript">
     
        $(document).ready(function () {
            $('#addProductPicture').click(function () {
                var pictureId = $("#@Html.FieldIdFor(model => model.AddPictureModel.PictureId)").val();
                var displayOrder = $("#@Html.FieldIdFor(model => model.AddPictureModel.DisplayOrder)").val();
                
                if (pictureId == 0) {
                    alert('Upload picture first');
                    return;
                }

                $('#addProductPicture').attr('disabled', true);
                $.ajax({
                    cache:false,
                    type: "POST",
                    url: "@(Url.Action("ProductPictureAdd", "Product"))",
                    data: { "pictureId": pictureId, "displayOrder": displayOrder, "productId": @Model.Id },
                    success: function (data) {
                         var productpicturesGrid = $("#productpictures-grid");
                         productpicturesGrid.data('tGrid').ajaxRequest();
                         $('#addProductPicture').attr('disabled', false);
                    },
                    error:function (xhr, ajaxOptions, thrownError){
                        alert('Failed to add product picture.')
                        $('#addProductPicture').attr('disabled', false);
                    }  
                });
            });
        });
        </script>        
            <table class="adminContent">
            <tr>
                <td class="adminTitle">
                    @Html.NopLabelFor(model => model.AddPictureModel.PictureId):
                </td>
                <td class="adminData">
                    @Html.EditorFor(model => model.AddPictureModel.PictureId)
                    @Html.ValidationMessageFor(model => model.AddPictureModel.PictureId)
                </td>
            </tr>
            <tr>
                <td class="adminTitle">
                    @Html.NopLabelFor(model => model.AddPictureModel.DisplayOrder):
                </td>
                <td class="adminData">
                    @Html.EditorFor(model => model.AddPictureModel.DisplayOrder)
                    @Html.ValidationMessageFor(model => model.AddPictureModel.DisplayOrder)
                </td>
            </tr>
            <tr>
                <td colspan="2" align="left">
                    <button type="button" name="addProductPicture" id="addProductPicture" class="t-button">
                        @T("Admin.Catalog.Products.Pictures.AddButton")</button>
                </td>
            </tr>
        </table>
        }
        else
        {
            @T("Admin.Catalog.Products.Pictures.SaveBeforeEdit")
        }
    }

@helper TabSpecificationAttributes()
    {
        if (Model.Id > 0)
        {

            /*hide "add spec" table if no attributes are defined*/
            if (Model.AddSpecificationAttributeModel.AvailableAttributes.Count > 0)
            {
                <div>
        @(Html.Telerik().Grid<ProductSpecificationAttributeModel>()
                    .Name("specificationattributes-grid")
                    .DataKeys(x =>
                    {
                        x.Add(y => y.Id).RouteKey("psaId");
                    })
                    .Columns(columns =>
                    {
                        columns.Bound(x => x.SpecificationAttributeName).Width(200).ReadOnly();
                        columns.Bound(x => x.SpecificationAttributeOptionName).Width(200).ReadOnly();
                        columns.Bound(x => x.AllowFiltering).Width(100);
                        columns.Bound(x => x.ShowOnProductPage).Width(100);
                        columns.Bound(x => x.DisplayOrder).Width(100);
                        columns.Command(commands =>
                        {
                            commands.Edit();
                            commands.Delete();
                        }).Width(180);

                    })
                    .Editable(x =>
                    {
                        x.Mode(GridEditMode.InLine);
                    })
                    .DataBinding(dataBinding =>
                    {
                        dataBinding.Ajax().Select("ProductSpecAttrList", "Product", new { productId = Model.Id })
                            .Update("ProductSpecAttrUpdate", "Product")
                            .Delete("ProductSpecAttrDelete", "Product");
                    })
                    .EnableCustomBinding(true))
    </div>
                <p>
                    <strong>@T("Admin.Catalog.Products.SpecificationAttributes.AddNew")</strong>
                </p>
                <script type="text/javascript">
     $(function() {
            $("#@Html.FieldIdFor(model => model.AddSpecificationAttributeModel.SpecificationAttributeId)").change(function() {
                var selectedItem = $(this).val();
                var ddlSpecOptions = $("#@Html.FieldIdFor(model => model.AddSpecificationAttributeModel.SpecificationAttributeOptionId)")
                $.ajax({
                    cache:false,
                    type: "GET",
                    url: "@(Url.Action("GetOptionsByAttributeId", "SpecificationAttribute"))",
                    data: { "attributeId": selectedItem },
                    success: function (data) {
                        ddlSpecOptions.html('');
                        $.each(data, function(id, option) {
                            ddlSpecOptions.append($('<option></option>').val(option.id).html(option.name));
                        });
                    },
                    error:function (xhr, ajaxOptions, thrownError){
                        alert('Failed to retrieve specification options.')
                    }  
                });
            });
        });

        $(document).ready(function () {
            $('#addProductSpec').click(function () {
                var specificationAttributeOptionId = $("#@Html.FieldIdFor(model => model.AddSpecificationAttributeModel.SpecificationAttributeOptionId)").val();
                var allowFiltering = $("#@Html.FieldIdFor(model => model.AddSpecificationAttributeModel.AllowFiltering)").is(':checked');
                var showOnProductPage = $("#@Html.FieldIdFor(model => model.AddSpecificationAttributeModel.ShowOnProductPage)").is(':checked');
                var displayOrder = $("#@Html.FieldIdFor(model => model.AddSpecificationAttributeModel.DisplayOrder)").val();
                
                $('#addProductSpec').attr('disabled', true);
                $.ajax({
                    cache:false,
                    type: "POST",
                    url: "@(Url.Action("ProductSpecificationAttributeAdd", "Product"))",
                    data: { "specificationAttributeOptionId": specificationAttributeOptionId, "allowFiltering": allowFiltering, "showOnProductPage": showOnProductPage, "displayOrder": displayOrder, "productId": @Model.Id },
                    success: function (data) {
                         var specificationAttributesGrid = $("#specificationattributes-grid");
                         specificationAttributesGrid.data('tGrid').ajaxRequest();
                         $('#addProductSpec').attr('disabled', false);
                    },
                    error:function (xhr, ajaxOptions, thrownError){
                        alert('Failed to add specification attribute.')
                        $('#addProductSpec').attr('disabled', false);
                    }  
                });
            });
        });
    </script>
                <table class="adminContent">
        <tr>
            <td class="adminTitle">
                @Html.NopLabelFor(model => model.AddSpecificationAttributeModel.SpecificationAttributeId):
            </td>
            <td class="adminData">
                @Html.DropDownListFor(model => model.AddSpecificationAttributeModel.SpecificationAttributeId, Model.AddSpecificationAttributeModel.AvailableAttributes)
                @Html.ValidationMessageFor(model => model.AddSpecificationAttributeModel.SpecificationAttributeId)
            </td>
        </tr>
        <tr>
            <td class="adminTitle">
                @Html.NopLabelFor(model => model.AddSpecificationAttributeModel.SpecificationAttributeOptionId):
            </td>
            <td class="adminData">
                @Html.DropDownListFor(model => model.AddSpecificationAttributeModel.SpecificationAttributeOptionId, Model.AddSpecificationAttributeModel.AvailableOptions)
                @Html.ValidationMessageFor(model => model.AddSpecificationAttributeModel.SpecificationAttributeOptionId)
            </td>
        </tr>
        <tr>
            <td class="adminTitle">
                @Html.NopLabelFor(model => model.AddSpecificationAttributeModel.AllowFiltering):
            </td>
            <td class="adminData">
                @Html.EditorFor(model => model.AddSpecificationAttributeModel.AllowFiltering)
                @Html.ValidationMessageFor(model => model.AddSpecificationAttributeModel.AllowFiltering)
            </td>
        </tr>
        <tr>
            <td class="adminTitle">
                @Html.NopLabelFor(model => model.AddSpecificationAttributeModel.ShowOnProductPage):
            </td>
            <td class="adminData">
                @Html.EditorFor(model => model.AddSpecificationAttributeModel.ShowOnProductPage)
                @Html.ValidationMessageFor(model => model.AddSpecificationAttributeModel.ShowOnProductPage)
            </td>
        </tr>
        <tr>
            <td class="adminTitle">
                @Html.NopLabelFor(model => model.AddSpecificationAttributeModel.DisplayOrder):
            </td>
            <td class="adminData">
                @Html.EditorFor(model => model.AddSpecificationAttributeModel.DisplayOrder)
                @Html.ValidationMessageFor(model => model.AddSpecificationAttributeModel.DisplayOrder)
            </td>
        </tr>
        <tr>
            <td colspan="2" align="left">
                <button type="button" name="addProductSpec" id="addProductSpec" class="t-button">
                    @T("Admin.Catalog.Products.SpecificationAttributes.AddButton")</button>
            </td>
        </tr>
    </table>
            }
            else
            {
                @T("Admin.Catalog.Products.SpecificationAttributes.NoAttributes")
            }
        }
        else
        {
            @T("Admin.Catalog.Products.SpecificationAttributes.SaveBeforeEdit")
        }
}